home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2005 June / PCpro_2005_06.ISO / files / opensource / amc / amc_install.exe / {app} / Scripts / Cinema - PTGate.ifs < prev    next >
Encoding:
Text File  |  2005-03-12  |  6.4 KB  |  219 lines

  1. (***************************************************
  2.  
  3. Ant Movie Catalog importation script
  4. www.antp.be/software/moviecatalog/
  5.  
  6. [Infos]
  7. Authors=O Guardiπo (bruno_mga@hotmail.com)
  8. Title=Cinema - PTGate
  9. Description=Movie importation script for :: Cinema - PTGate ::
  10. Site=www.cinema.ptgate.pt
  11. Language=PT
  12. Version=1.3 (8 Fev 2005)
  13. Requires=3.5.0
  14. Comments=Script feito por O Guardiπo (bruno_mga@hotmail.com) para o site "www.cinema.ptgate.pt" |
  15. License=This program is free software; you can redistribute it and/or modify it under the  terms of the GNU General Public License as published by the Free Software Foundation;  either version 2 of the License, or (at your option) any later version. |
  16. GetInfo=1
  17.  
  18. [Options]
  19.  
  20. ***************************************************)
  21.  
  22. program PTGate;
  23.  
  24. var
  25.   MovieName: string;
  26.   MovieURL: string;
  27. function HTMLRemove(Value: String): String;
  28. begin
  29.   HTMLDecode(Value);
  30.   HTMLRemoveTags(Value);
  31.   Value := Trim(Value);
  32.   result := Value;
  33. end;
  34.  
  35. procedure AnalyzeFilmPage(Address: String);
  36. var
  37.   Page : TStringList;
  38.   Line, Value : string;
  39.   LineNr, BeginPos, EndPos: Integer;
  40.   url_imdb:string;
  41.   nome_orig:string;
  42.   nome_trad:string;
  43.   ano:string;
  44.   pais:string;
  45.   genero:string;
  46.   realizac:string;
  47.   Interpretes:string;
  48.   descricao:string;
  49.   capa:string;
  50. begin
  51.   Page := TStringList.Create;
  52.   Address:='http://cinema.ptgate.pt/filme.php?code='+Address;
  53.   Page.Text := GetPage(Address);
  54.   SetField(fieldURL, Address);
  55.  
  56.   //obter nome do filme
  57.   LineNr := FindLine('</b><br><b class=subtitle>', Page, 0);
  58.   if LineNr<>-1 then
  59.   begin
  60.     Value := Page.GetString(LineNr);
  61.     BeginPos:= pos('<b class=title>',value)+15;
  62.     EndPos := pos('</b><br>', value)+8;
  63.     nome_orig:=copy(value,BeginPos,EndPos-BeginPos);
  64.  
  65.     //por o the no principio do nome
  66.     if pos(', The</b>',nome_orig) <>0 then
  67.     begin
  68.       url_imdb:=HTMLRemove(nome_orig);
  69.       nome_orig:= StringReplace(nome_orig, ', The</b><br>', '');
  70.       nome_orig:=HTMLRemove(nome_orig);
  71.       nome_orig:='The '+Copy(nome_orig,1,length(nome_orig));
  72.     end;
  73.  
  74.     nome_orig:=HTMLRemove(nome_orig);
  75.     SetField(fieldOriginalTitle, nome_orig);
  76.   end;
  77.  
  78.   //obter nome traduzido
  79.   BeginPos := pos('<b class=subtitle>', value)+18;
  80.   value:= Copy(value,BeginPos,length(value));
  81.   EndPos := pos('</b>',value);
  82.   nome_trad:=Copy(value,1,EndPos);
  83.   nome_trad:=HTMLRemove(nome_trad);
  84.   SetField(fieldTranslatedTitle, nome_trad);
  85.   value:=Copy(value,EndPos,length(value));
  86.  
  87.   //ano
  88.   BeginPos := pos('<br><br><b>', value)+22;
  89.   value:= Copy(value,BeginPos,length(value));
  90.   EndPos := pos('<br><br><b>',value);
  91.   ano:=Copy(value,1,EndPos);
  92.   ano:=HTMLRemove(ano);
  93.   SetField(fieldYear, ano);
  94.   value:=Copy(value,EndPos,length(value));
  95.  
  96.   //paφs
  97.   BeginPos := pos('<br><b>paφs</b><br>', value)+19;
  98.   value:= Copy(value,BeginPos,length(value));
  99.   EndPos := pos('<br><br><b>',value);
  100.   pais:=Copy(value,1,EndPos);
  101.   pais:=HTMLRemove(pais);
  102.   SetField(fieldCountry, pais);
  103.   value:=Copy(value,EndPos,length(value));
  104.  
  105.   //gΘnero
  106.   BeginPos := pos('<br><b>gΘnero</b><br>', value)+21;
  107.   value:= Copy(value,BeginPos,length(value));
  108.   EndPos := pos('<br><br><b>',value);
  109.   genero:=Copy(value,1,EndPos);
  110.   genero:=HTMLRemove(genero);
  111.   SetField(fieldCategory, genero);
  112.   value:=Copy(value,EndPos,length(value));
  113.  
  114.  //realizaτπo
  115.   BeginPos := pos('<br><br><b>realizaτπo</b><br>', value)+29;
  116.   value:= Copy(value,BeginPos,length(value));
  117.   EndPos := pos('<br><br><b>',value);
  118.   realizac:=Copy(value,1,EndPos);
  119.   realizac:=HTMLRemove(realizac);
  120.   SetField(fieldDirector, realizac);
  121.   value:=Copy(value,EndPos,length(value));
  122.  
  123.   //intΘrpretes
  124.   BeginPos := pos('<br><br><b>intΘrpretes</b><br>', value)+30;
  125.   value:= Copy(value,BeginPos,length(value));
  126.   EndPos := pos('<br><br><b>',value);
  127.   Interpretes:=Copy(value,1,EndPos);
  128.   Interpretes:= StringReplace(Interpretes, '<br>', ', ');
  129.   Interpretes:=HTMLRemove(Interpretes);
  130.   SetField(fieldActors, Interpretes);
  131.   value:=Copy(value,EndPos,length(value));
  132.   
  133.   //descriτπo
  134.   BeginPos := pos('<br><br><b>sinopse</b><br>', value)+26;
  135.   if BeginPos<>26 then
  136.   begin
  137.     value:= Copy(value,BeginPos,length(value));
  138.     EndPos := pos('<br><br><br>',value);
  139.     descricao:=Copy(value,1,EndPos);
  140.     descricao:=HTMLRemove(descricao);
  141.     SetField(fieldDescription, descricao);
  142.   end;
  143.  
  144.   //capa
  145.   LineNr := FindLine('width=100 height=150>', Page, 0);
  146.   Value := Page.GetString(LineNr);
  147.   BeginPos:=pos('<img src=',value)+10;
  148.   EndPos:=pos(' width=100 height=150>',value)-1;
  149.   value:=Copy(value,BeginPos,EndPos-BeginPos);
  150.   value:='http://cinema.ptgate.pt/'+value;
  151.   GetPicture(Value);
  152.  
  153. end;
  154.  
  155.  
  156.  
  157. function FindLine(Pattern: string; List: TStringList; StartAt: Integer): Integer;
  158. var
  159.   i: Integer;
  160. begin
  161.   result := -1;
  162.   if StartAt < 0 then
  163.     StartAt := 0;
  164.   for i := StartAt to List.Count-1 do
  165.     if Pos(Pattern, List.GetString(i)) <> 0 then
  166.     begin
  167.       result := i;
  168.       Break;
  169.     end;
  170. end;
  171.  
  172. procedure AnalyzePage(Address: string);
  173. var
  174.   Page: TStringList;
  175.   LineNr, StartPos, EndPos: Integer;
  176.   Line: string;
  177.   x:integer;
  178.   MovieAddress, findMovieName,linedown : string;
  179.   guardar,url, nome_filme:string;
  180. begin
  181.   PickTreeClear;
  182.   Page := TStringList.Create;
  183.   Page.Text := GetPage(Address);
  184.  
  185.   if (pos('Nπo foram encontrados filmes ou pessoas que satisfaτam a sua pesquisa.', Page.Text)<>-1) then   //se existe
  186.   begin
  187.       LineNr := FindLine('filme.php?code=', Page, LineNr);
  188.       Line := Page.GetString(LineNr);
  189.     repeat
  190.         StartPos := pos('filme.php?code=', Line)+15;
  191.         if StartPos=15 then break;
  192.  
  193.         guardar:=Copy(line,StartPos+1,9999);
  194.         line:=Copy(line,StartPos,9999);    
  195.         StartPos := pos('>',line)+1;
  196.         url:=(copy(line,1,StartPos-3));
  197.         EndPos := pos('</a>',line)-1;
  198.         line := copy(Line, StartPos, EndPos - StartPos+1);
  199.           nome_filme:=line;
  200.         PickTreeAdd(nome_filme, url);
  201.         line:=guardar;
  202.     until (nome_filme='');
  203.  
  204.     if PickTreeExec(Address) then
  205.       AnalyzeFilmPage(Address);
  206.     Page.Free;
  207.   end
  208. end;
  209. begin
  210.   PickListClear;
  211.   MovieName := GetField(fieldOriginalTitle);
  212.   if Input('Importar do cinema.ptgate.pt', 'Escreva o nome do filme:', MovieName) then begin
  213.   //espaτo nπo sπo permitidos
  214.   MovieName := StringReplace(MovieName, ' ', '%20');
  215.   AnalyzePage('http://cinema.ptgate.pt/pesquisa.php?pesquisa='+MovieName);
  216.   end;
  217. end.
  218.  
  219.